package data.join.com.database.bean;

import java.util.List;

import data.join.com.database.GreenDao;

/**
 * Created by Administrator on 2017/10/16.
 */

public class PhotoPref {

    public static int HANDLE_STATE_CREATE = 0;
    public static int HANDLE_STATE_HANDLED = 1;

    private static String TAG = "PhotoPref";
    private static PhotoPref mInstance;

    private PhotoBeanDao photoBeanDao;

    private PhotoPref(){
        photoBeanDao = GreenDao.getInstance().sDaoSession.getPhotoBeanDao();
    }

    public static synchronized PhotoPref getInstance() {
        if (mInstance == null) {
            mInstance = new PhotoPref();
        }
        return mInstance;
    }

    public void insertPhotoBean(PhotoBean photoBean){
        photoBeanDao.insert(photoBean);
    }

    public PhotoBean getLastUnHandleCommand(){
        PhotoBean photoBean = null;
        List<PhotoBean> list;

        list = photoBeanDao.queryBuilder()
                .where(PhotoBeanDao.Properties.HandleState.eq(HANDLE_STATE_CREATE))
                .orderDesc(PhotoBeanDao.Properties.Id)
                .limit(1)
                .list();

        if(list != null && list.size() > 0){
            photoBean = list.get(0);
        }

        return photoBean;
    }

    public void updatePhotoBean(PhotoBean fileUpload){
        photoBeanDao.update(fileUpload);
    }

    public boolean existPhotoBean(String commandId){
        return photoBeanDao.queryBuilder().where(PhotoBeanDao.Properties.CommandId.eq(commandId)).count()>0;
    }
}
